package com.lty.jeeg.server.modules.fas.dao;

import java.util.List;
import java.util.Map;

import com.lty.jeeg.server.modules.fas.dto.OrderDTO;
import com.lty.jeeg.server.modules.fas.export.OrderExportEntity;
import org.apache.ibatis.annotations.*;

import org.springframework.stereotype.Repository;

import com.lty.jeeg.server.modules.fas.model.Order;

/**
 * @author : ZL
 * @date : 2019-02-13 10:41:32
 * Description : 需求单
 */
@Mapper
@Repository
public interface OrderDao {

    /**
     * 根据ID获取
     * @param id ID
     * @return bean
     */
    @Select("select t.* from fas_order t where t.id = #{id} ")
    Order getById(Long id);

    /**
     * 删除
     * @param id ID
     * @return 1/0
     */
    @Delete("delete from fas_order where id = #{id}")
    int delete(Long id);

    /**
     * 修改
     * @param order ID
     * @return 1/0
     */
    int update(Order order);

    /**
     * 保存
     * @param order bean
     * @return ID
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into fas_order(name, originatorId, originatorName, orderType, originatorOfficeId, originatorOfficeName, companyId, wishPayDate, createBy, updateBy,remark, isDeleted, totalPrice,  screenshotPath) values(#{name}, #{originatorId}, #{originatorName}, #{orderType}, #{originatorOfficeId}, #{originatorOfficeName}, #{companyId}, #{wishPayDate},  #{createBy}, #{updateBy},#{remark}, #{isDeleted}, #{totalPrice}, #{screenshotPath})")
    Long save(Order order);

    /**
     * 计数
     * @param params 筛选条件
     * @return 总数
     */
    int count(@Param("params") Map<String, Object> params);

    /**
     * 列表
     * @param params 筛选条件
     * @param offset 页码
     * @param limit 分页数目
     * @return beanList
     */
    List<Order> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    /**
     * 修改订单审批状态
     * @return
     */
    @Update("UPDATE fas_order t SET t.orderType=#{type} WHERE t.id=#{id}")
    @ResultType(int.class)
    int changeType(@Param("id")Long id,@Param("type")String type);

    /**
     * 导出需求单数据
     * @param orderDTO
     * @return
     */
    List<OrderExportEntity> getExportDatas(OrderDTO orderDTO);
}
